import type { Module, ActionContext } from 'vuex'
import type { AxiosResponse } from 'axios'
import type { noticeStateType } from './typings'
import {
  noticeListGet,
  noticeRemovePost,
  getDeptUserTreeGet,
  noticeAddPost,
  noticePushNoticePost,
  noticePushNoticeByIdPost
} from '~/api/system/notice'

const work: Module<noticeStateType, noticeStateType> = {
  namespaced: true,
  state: {},
  getters: {},
  mutations: {},
  actions: {
    // 系统通告-列表
    async NoticeListGet<S, T>(_: ActionContext<S, T>, params: T) {
      return await noticeListGet<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 删除系统通告
    async NoticeRemovePost<S, T>(_: ActionContext<S, T>, params: T) {
      return await noticeRemovePost<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 用户组织树
    async GetDeptUserTreeGet<S, T>(_: ActionContext<S, T>, params: T) {
      return await getDeptUserTreeGet<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 系统通告 - 保存
    async NoticeAddPost<S, T>(_: ActionContext<S, T>, params: T) {
      return await noticeAddPost<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 系统通告 - 发布
    async NoticePushNoticePost<S, T>(_: ActionContext<S, T>, params: T) {
      return await noticePushNoticePost<T>(params).then((res: AxiosResponse) => res?.data)
    },
    // 系统通告 - 根据ID发布
    async NoticePushNoticeByIdPost<S, T>(_: ActionContext<S, T>, params: T) {
      return await noticePushNoticeByIdPost<T>(params).then((res: AxiosResponse) => res?.data)
    }
  }
}

export default work
